package com.lineng.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.alibaba.fastjson.JSON;
import com.lineng.pojo.DownSource;
import com.lineng.service.DownSourceService;

@Controller
public class DownSourceController {

	@Autowired
	DownSourceService downSourceService;

	/**
	 * 获取素材
	 * 
	 * @return
	 */
	@RequestMapping(value = "/getDownSource", method = RequestMethod.GET, produces = "text/json;charset=UTF-8")
	@ResponseBody
	public String getDownSource() {
		List<DownSource> downsources = downSourceService.getDownSource();
		return JSON.toJSONString(downsources);

	}

	/**
	 * 添加素材
	 * 
	 * @param downsource
	 * @param file
	 * @return
	 */
	@RequestMapping(value = "/insertDownSource", method = RequestMethod.POST, produces = "text/json;charset=UTF-8")
	@ResponseBody
	public String insertDownSource(DownSource downsource, MultipartFile file, HttpServletRequest request) {
		return JSON.toJSONString(downSourceService.insertDownSource(downsource, file,
				(String) request.getSession().getAttribute("username")));

	}

	/**
	 * 删除素材
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "/deleteDownSource", method = RequestMethod.POST, produces = "text/json;charset=UTF-8")
	@ResponseBody
	public String deleteDownSource(Integer[] idList) {
		return JSON.toJSONString(downSourceService.deleteDownSource(idList));

	}

}
